<template>
	<view class="content">
		<view class="tabs">
			<view :class="tab === i.value ? 'active' : ''" v-for="i in tabs" @click="tabClick(i)">{{i.label}}</view>
		</view>
		<view class="list">
			<view class="item" v-for="i in list"  :key="i.id">
				<view>{{i.task && i.task.name}}</view>
				<view>{{i.created_at}}</view>
				<view :style="{
					background:color[i.status]
				}">{{obj[i.status]}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		getAction
	} from '../../../common/request'
	export default {
		data() {
			return {
				tabs: [{
						label: '全部',
						value: ''
					},
					{
						label: '审核中',
						value: 0
					},
					{
						label: '已完成',
						value: 1
					},
					{
						label: '完成失败',
						value: 2
					},
				],
				obj:{
					0:'审核中',
					1:'已完成',
					2:'完成失败',
				},
				color:{
					0:'red',
					1:'#7ecd9f',
					2:'#fb806d',
				},
				tab: '',
				list: [],
				current: 1,
				finash: false
			}
		},
		onLoad() {
			this.reload()
		},
		onReachBottom() {
			this.current++
			this.getList()
		},
		methods: {
			tabClick(i) {
				this.tab = i.value
				this.reload()
			},
			reload() {
				this.current = 1
				this.list = []
				this.finash = false
				this.getList()
			},
			getList() {
				if (this.finash) return
				uni.showLoading({
					mask: true
				})
				getAction('/user/task', {
					page: this.current,
					pageSize: 10,
					status: this.tab
				}).then(res => {
					uni.hideLoading()
					this.list = this.list.concat(res.data.data)
					this.finash = res.data.last_page == res.data.current_page
				})
			}
		}
	}
</script>

<style lang="scss">
	.content {
		padding: 30rpx;
	}

	.tabs {
		display: flex;
		flex-wrap: wrap;
		margin-bottom: 40rpx;

		>view {
			height: 56rpx;
			border-radius: 28rpx 28rpx 28rpx 28rpx;
			line-height: 58rpx;
			text-align: center;
			padding: 0 20rpx;
			margin-right: 20rpx;

		}

		>view.active {
			background: #FF5035;
			color: #FFF;
		}
	}

	.list {
		.item {
			min-height: 160rpx;
			background: #F5F5F5;
			border-radius: 10rpx 10rpx 10rpx 10rpx;
			opacity: 1;
			padding: 24rpx 32rpx;
			margin-bottom: 40rpx;
			color: #2B2B2B;
			position: relative;

			>view:nth-of-type(1) {

				font-size: 28rpx;
				padding-right: 230rpx;
			}

			>view:nth-of-type(2) {
				position: absolute;
				top: 28rpx;
				right: 20rpx;
				font-size: 24rpx;

			}

			>view:nth-of-type(3) {
				position: absolute;
				bottom: 20rpx;
				right: 20rpx;
				background: #3AC0F4;
				height: 46rpx;
				width: 148rpx;
				border-radius: 23rpx 23rpx 23rpx 23rpx;
				line-height: 46rpx;
				text-align: center;
				color: #FFFFFF;
				font-size: 22rpx;

			}
		}
	}
</style>